//////////////////////////////////////////////////////////////////////////////////
//	Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#ifndef __XML_GUI_YG_H__
#define __XML_GUI_YG_H__

#include "def.h"
#include <wx/vscroll.h> 

class CXMLGUIPanel: public  wxVScrolledWindow 
{
public:
								CXMLGUIPanel(wxWindow* parent, IGUIXMLExecutor* pEx);
	virtual						~CXMLGUIPanel(void);

	void						ShowAdvanced(bool bShow, const std::string& strCaps);
	void						SetStatXML(const std::string& strXML);
	void						SetCapsXML(const std::string& strXML) { m_strCapsXML=strXML; }

protected:
	virtual wxCoord				OnGetRowHeight  ( size_t  row   )  const { return 10; }

protected:
	void						BuildUI();
	void						UpdateUIVals();

protected:
	void						OnBtnClicked(wxCommandEvent& ev);
	void						OnChanged(wxCommandEvent& ev);


private:
	void						RenderBlock(class CMarkupSTL& doc);
	void						RenderItem(class CMarkupSTL& doc, wxSizer* pSizer, wxSizer* pSizerParent);
	class wxWindow*				RenderRadioBox(class CMarkupSTL& doc, wxSizer* pSizer, int nID);
	class wxWindow*				RenderCheckBox(class CMarkupSTL& doc, wxSizer* pSizer, int nID);
	class wxWindow*				RenderButton(class CMarkupSTL& doc, wxSizer* pSizer, int nID);
	class wxWindow*				RenderInput(class CMarkupSTL& doc, wxSizer* pSizer, int nID);
	void						RenderLine(class CMarkupSTL& doc, wxSizer* pSizer);

private:
	typedef struct tagGUIITEM
	{
		std::string		strGroupID;

		std::string		strID;
		std::string		strLookUpVal; //stat must have the same val
		std::string		strValueLookUpName;
		std::string		strType;
		std::string		strCMD;		//What to do if item selected/clicked
		std::string		strApplyTo; //Scope of apply button

		//combo
		std::string		strCMDOn;	//If have dif for on/off
		std::string		strCMDOff;

		//input
		std::string		strInputType;
		std::string		strInputFrom;
		std::string		strInputTo;


		class wxWindow*	pWND;
	}GUIITEM;

	typedef std::list<GUIITEM>	GUIITEMS;
	GUIITEMS					m_lstGUIItems;

	bool						LookUpItem(const std::string& strID, GUIITEM& item ) const;
	bool						LookUpItem(class wxWindow*	pWND, GUIITEM& item ) const;

	std::string					LookUpValueFromStatXML(const std::string& strName) const;
	void						ApplyValue( GUIITEM& item,  const std::string& strVal);
	void						ApplyControlValue( GUIITEM& item,  const std::string& strVal);
	std::string					BuildItemAction(const GUIITEM& item) const;
	std::string					BuildItemVal(const GUIITEM& item) const;
	std::string					BuildItemActionXML(const GUIITEM& item) const;
	std::string					BuildItemGroupXML(const GUIITEM& item) const;

	void						LoadData();
	void						SaveData();

private:
	std::string					m_strCapsXML;
	std::string					m_strStatXML;
	class wxFlexGridSizer*		m_pSizer;

	const int					m_nFlags;
	const int					m_nBorder;

	bool						m_bDirty;
	int							m_nId;
	IGUIXMLExecutor*			m_pEx;

	class wxCheckBox*			m_pStartUP;	
};

#endif //__XML_GUI_YG_H__